<template>
  <div id="app" v-cloak>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ticket: "",
      corpId: "",
      nonce: "",
      timeStamp: "",
      url: "",
      signature: "",
      agentId: ""
    };
  },
  created: function() {
    this.url = window.location.protocol + "//" + window.location.host + "/";
    this.timeStamp = new Date().getTime();
    this.nonce = Math.random() + "abc";
    this.GetJsApiTicket();
  },
  methods: {
    async GetJsApiTicket() {
      var result = await this.$httpd.get("/DingDingSecurity/GetJsapiTicket");
      if (result.status != 200) {
        this.$message.error("获取下拉列表数据失败");
      } else {
        this.ticket = result.data.ticket;
        this.corpId = result.data.corpId;
        this.agentId = result.data.agentId;
        this.GetJsApiSingnature(
          this.ticket,
          this.nonce,
          this.timeStamp,
          this.url
        );
        this.JainQuan();
      }
    },
    GetJsApiSingnature(ticket, nonce, timeStamp, url) {
      let plainTex =
        "jsapi_ticket=" +
        ticket +
        "&noncestr=" +
        nonce +
        "&timestamp=" +
        timeStamp +
        "&url=" +
        url;

      this.signature = this.$CryptoJS.SHA1(plainTex).toString();
    },
    JainQuan() {
      //===钉钉鉴权
      this.$dd.config({
        agentId: this.agentId,
        corpId: this.corpId, //必填，企业ID
        timeStamp: this.timeStamp, // 必填，生成签名的时间戳
        nonceStr: this.nonce, // 必填，生成签名的随机串
        signature: this.signature, // 必填，签名
        jsApiList: [
          "runtime.info",
          "device.notification.prompt",
          "biz.chat.pickConversation",
          "device.notification.confirm",
          "device.notification.alert",
          "device.notification.prompt",
          "biz.chat.open",
          "biz.util.open",
          "biz.user.get",
          "biz.contact.choose",
          "biz.telephone.call",
          "biz.util.uploadImage",
          "biz.ding.post"
        ] // 必填，需要使用的jsapi列表，注意：不要带dd。
      });

      // this.$dd.ready(() => {
      //   this.$dd.runtime.permission.requestAuthCode({
      //     corpId: this.corpId, // 企业id
      //     onSuccess: function(info) {
      //     console.log(info.code);
          
      //     }
      //   });
      // });

      // 查看鉴权错误信息
      this.$dd.error(function(err) {
        alert("dd error: " + JSON.stringify(err));
      });
    }
  }
};
</script>
 
<style>
</style>
